package com.study.samsung.Dao.htDao;

import com.study.samsung.Entity.htEntity.Admin;
import com.study.samsung.Utils.RowMapper;
import com.study.samsung.Utils.SQLHelper;

import java.sql.ResultSet;
import java.sql.SQLException;

public class AdminDao {
    private SQLHelper helper = new SQLHelper();

    public Admin selectByLogin(String adminaccount){
        String sql = "select * from admin where adminaccount=?";
        return helper.one(sql,new AdminRowMapper(),adminaccount);
    }
    public Integer doUpdate(Admin a){
        String sql = "update admin set adminaccount=?,adminpwd=?";
        return helper.update(sql,a.getAdminaccount(),a.getAdminpwd());
    }

    class AdminRowMapper implements RowMapper<Admin>{

        @Override
        public Admin map(ResultSet rs) throws SQLException {
            return new Admin(rs.getInt("adminid"),
                    rs.getString("adminaccount"),
                    rs.getString("adminpwd"),
                    rs.getString("adminstate"));
        }
    }
}
